package cn.itsource.crm.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//对swagger进行配置
//相当于自己创建一个applicationContext.xml
@Configuration
//开启springmvc和swagger配置
@EnableWebMvc
@EnableSwagger2
public class SwaggerConfig {
    //相当于<bean class='Docket'></bean>
    @Bean
    public Docket api(){
        //配置
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(this.apiInfo())//配置信息
                .select() //得到builder对象
                .apis(RequestHandlerSelectors.basePackage("cn.itsource.crm.web.controller"))//扫描controller
                .paths(PathSelectors.any())//查找包下所有路径
                .build();
    }
    

    private ApiInfo apiInfo(){
         @SuppressWarnings("deprecation")
        ApiInfo info=new ApiInfo(
                 "4S维修管理系统CRUD测试",
                 "一个完整的crud",
                 "v1",
                 "http://www.itsource.cn",
                 "ganggang",
                 "apache",
                 "http://www.itsource.cn");
         return info;
    }
}